package org.javver.xmpp;

import org.apache.log4j.Logger;

import java.util.Properties;
import java.io.File;
import java.io.IOException;
import java.io.FileOutputStream;

/**
 * @author Pawel 'Crooveck' Tomaszewski
 */

public class XMPPProperties extends Properties {

    private static Logger logger = Logger.getLogger(XMPPProperties.class);

    private static final String PROPERTIES_FILE = "xmpp.properties";
    private static XMPPProperties properties = null;

    public static String HOST, JID, USERNAME, PASSWORD;
    public static Integer PORT;


    static {
        try {
            properties = new XMPPProperties();

        } catch (IOException e) {
            logger.info(e.getStackTrace());
        }

        JID = properties.getProperty("JID");
        USERNAME = properties.getProperty("USERNAME");
        HOST = properties.getProperty("HOST");
        PASSWORD = properties.getProperty("PASSWORD");
        PORT = Integer.parseInt(properties.getProperty("PORT"));
    }

    private XMPPProperties() throws IOException {
        this.load(XMPPProperties.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE));
    }

    public static void storeProperties() throws IOException {
        properties.store(new FileOutputStream(new File(PROPERTIES_FILE)), null);

        logger.info("New properties stored in " + PROPERTIES_FILE);

    }
}
